﻿using System.Security.Cryptography.X509Certificates;

namespace CodingExercises._21_30;

public class AreParenthesesBalanced
{
    // 检查括号是否平衡
    public static bool Method(string expression)
    {
        var stk = new Stack<char>();
        foreach (var item in expression)
        {
            if (item == '(')
            {
                stk.Push('(');
            }
            else if (item == ')')
            {
                if (stk.Count == 0)
                {
                    return false;
                }

                stk.Pop();
            }
        }

        return stk.Count == 0;
    }
}